home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / utility / umult64.c < prev    next >
C/C++ Source or Header  |  1996-09-12  |  2KB  |  84 lines

  1. /*
  2.     $Id: umult64.c,v 1.1 1996/08/31 12:58:14 aros Exp $
  3.     $Log: umult64.c,v $
  4.     Revision 1.1  1996/08/31 12:58:14  aros
  5.     Merged in/modified for FreeBSD.
  6.  
  7.     Desc: Unsigned 64-bit product of two 32-bit numbers.
  8.     Lang: english
  9. */
  10. #include "utility_intern.h"
  11.  
  12. /*****************************************************************************
  13.  
  14.     NAME */
  15.         #include <clib/utility_protos.h>
  16.  
  17.         __AROS_LH2(ULONG, UMult64,
  18.  
  19. /*  SYNOPSIS */
  20.         __AROS_LHA(unsigned long, arg1, D0),
  21.         __AROS_LHA(unsigned long, arg2, D1),
  22.  
  23. /*  LOCATION */
  24.         struct UtilityBase *, UtilityBase, 34, Utility)
  25.  
  26. /*  FUNCTION
  27.         Compute the unsigned 64-bit product of arg1 * arg2.
  28.  
  29.     INPUTS
  30.         arg1, arg2  -   32 bit unsigned numbers.
  31.  
  32.     RESULT
  33.         arg1 * arg2
  34.  
  35.     NOTES
  36.  
  37.     EXAMPLE
  38.  
  39.     BUGS
  40.         There is a problem under the current system in that it is very
  41.         hard to return a 64-bit value.
  42.  
  43.     SEE ALSO
  44.         utility/SMult32(), utility/UMult32(), utility/SMult64()
  45.  
  46.     INTERNALS
  47.         This is essentially UMult32(), but without the code to calculate
  48.         the product of the high 32 bits of the multiplicands.
  49.  
  50.         In fact all that is added is the code to calculate 2^32 * ac.
  51.  
  52.     HISTORY
  53.         29-10-95    digulla automatically created from
  54.                             utility_lib.fd and clib/utility_protos.h
  55.         18-08-96    iaint   Modified UMult32().
  56.  
  57. *****************************************************************************/
  58. {
  59.     __AROS_FUNC_INIT
  60.  
  61. #ifdef HAS_64BITMULU
  62.     return arg1 * arg2;
  63. #else
  64.  
  65.     unsigned long long product;
  66.     UWORD a0, a1, b0, b1;
  67.  
  68.     a1 = (arg1 >> 16) & 0xffff;
  69.     a0 = arg1 & 0xffff;
  70.     b1 = (arg2 >> 16) & 0xffff;
  71.     b0 = arg2 & 0xffff;
  72.  
  73.     /* In case number is quite small an optimization */
  74.     if(a1 && b1)
  75.         product = (unsigned long long)(a1 * b1) << 32;
  76.     else
  77.         product = 0;
  78.  
  79.     product += (((a1 * b0) + (a0 * b1)) << 16) + (a0 * b0);
  80.     return product;
  81. #endif
  82.     __AROS_FUNC_EXIT
  83. } /* UMult64 */
  84.